<template>
  <!--参数取值必须在标签内。不能单独在template内-->
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>个人就业信息</span>
        <el-button style="float: none; padding: 3px 0" type="text" v-on:click="workadd()">录入就业信息</el-button>
        <el-button style="float: none; padding: 3px 0" type="text" v-on:click="workchange()">修改保存信息</el-button>
        <el-button style="float: none; padding: 3px 0" type="text" v-on:click="workdelete()">删除就业信息</el-button>
      </div>
      <div class="text item">
        {{'学号：'+id}}
        {{'姓名：'}}<el-input style="width:140px" v-model="userform.name" ></el-input>
        {{'专业：'}}<el-input style="width:140px" v-model="userform.major" ></el-input>
        {{'性别：'}}<el-input style="width:140px" v-model="userform.gender" ></el-input>
        {{'籍贯/生源地：'}}<el-input style="width:140px" v-model="userform.native_place" ></el-input>
      </div>
      <div class="text item">
        {{'毕业去向(升学，出国，就业、地域、单位/行业)：'}}<el-input style="width:250px" v-model="userform.intention" ></el-input>
      </div>
      <div class="text item">
        {{'当前状态(拟就业、拟升学、拟出国、已出国、已就业、已升学)：'}}<el-input style="width:250px" v-model="userform.state" ></el-input>
      </div>
      <div class="text item">
        {{'实际毕业去向（升学/出国/就业、单位）：'}}  <el-input style="width:250px" v-model="userform.actual" ></el-input>
      </div>
      <div class="text item">
        {{'备注（自定义输入特殊情况）：'}}  <el-input style="width:300px" v-model="userform.remark" ></el-input>
      </div>
      <div class="text item">
        {{'是否上报生源（1-是，0-否）：'}}<el-input style="width:250px" v-model="userform.report" ></el-input>
      </div>
      <div class="text item">
        {{'是否完成派遣（1-是，0-否）：'}}  <el-input style="width:250px" v-model="userform.finish" ></el-input>
      </div>
    </el-card>
  </div>
</template>

<script>
import { basequery } from "@/api/basequery.js";
import conf from "@/utils/config.js";
const { token } = conf;
export default {
  name: "Work",
  props:['id'],
  data() {
    return {
        userform:{        id:'',
                          name: '',
                          major:"",
                          gender:"",
                          native_place:"",
                          intention:"",
                          state:"",
                          actual:"",
                          remark:"",
                          report:"",
                          finish:""},
        }
  },
  mounted:function(){
    var url='/work/query';
        this.$http.get(url,{params:this.id}).then((res) =>{
                console.log(res);
                var jsonObject = res.data;
                this.userform=jsonObject.jobs[0];
            })
            .catch((err) => {
                          this.$notify.error({
                            title: "错误",
                            message: "服务器内部错误",
                          });
                        });
  },
  methods: {
    show() {
      console.log(this.$route.params.id)
    },
    workchange(){
    var url='/work/change';
    this.$http.put(url,this.userform).then((res) =>{
            console.log(res);
            var jsonObject = res.data;
            if(jsonObject.code==200){
             this.$notify.success({
                              title: "提示",
                              message: jsonObject.message,
                            });
            }
            else if(jsonObject.code==400){
            this.$notify.error({
                               title: "提示",
                               message: jsonObject.message,
                            });
            }
        })
        .catch((err) => {
                      this.$notify.error({
                        title: "错误",
                        message: "服务器内部错误",
                      });
                    });
    },
    workadd(){
       var url='/work/add';
       this.$http.post(url,this.userform).then((res) =>{
                   console.log(res);
                   var jsonObject = res.data;
                   if(jsonObject.code==200){
                    this.$notify.success({
                                     title: "提示",
                                     message: jsonObject.message,
                                   });
                   }
                   else if(jsonObject.code==400){
                   this.$notify.error({
                                      title: "提示",
                                      message: jsonObject.message,
                                   });
                   }
               })
               .catch((err) => {
                             this.$notify.error({
                               title: "错误",
                               message: "服务器内部错误",
                             });
                           });
    },
    workdelete(){
       var url='/work/delete';
       this.$http.delete(url,{params:this.userform}).then((res) =>{
                   console.log(res);
                   var jsonObject = res.data;
                   if(jsonObject.code==200){
                    this.$notify.success({
                                     title: "提示",
                                     message: jsonObject.message,
                                   });
                   }
                   else if(jsonObject.code==400){
                   this.$notify.error({
                                      title: "提示",
                                      message: jsonObject.message,
                                   });
                   }
               })
               .catch((err) => {
                             this.$notify.error({
                               title: "错误",
                               message: "服务器内部错误",
                             });
                           });
    }
  }
}
</script>
<style scoped>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}
.clearfix:after {
  clear: both
}

.box-card {
  width: 1200px;
}
</style>
